﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace MBTest
{
    [TestFixture]
    public class PingPongTest2
    {
        private class Ping
        {
            int m_count = 5;
            public Ping()
            {
                Actor.Receive<int>(Topics.Pong, (s, e) =>
                {
                    Console.WriteLine("Ping received pong :" + e.Message);

                    if (--this.m_count > 0)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Ping sent  :" + m_count.ToString());
                        Actor.Post<int>(Topics.Ping, m_count);
                    }
                    else
                    {
                        Console.WriteLine("Finished");
                        Actor.Exit<Ping>(Topics.Ping);
                    }
                });
            }

            public void Start()
            {
                Console.WriteLine("Ping sent  :" + m_count.ToString());
                Actor.Post<int>(Topics.Ping, m_count);
            }
        }

        private class Pong
        {
            public Pong()
            {
                Actor.Receive<int>(Topics.Ping, (s, e) =>
                {
                    Console.WriteLine("Pong received ping :" + e.Message.ToString());
                    Console.WriteLine("Pong sent  :" + e.Message.ToString());
                    Actor.Post<int>(Topics.Pong, e.Message);
                });
            }
        }

        [Test]
        public void Test()
        {
            var ping = new Ping();
            var pong = new Pong();
            ping.Start();
        }
    }
}
